package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class ConexaoBD {
	
	private static final String DRIVER 
	="com.microsoft.sqlserver.jdbc.SQLServerDriver";
	
	private static final String URL 
	="jdbc:sqlserver://localhost:1433; databasename=E_COMERCE";
	
	private static final String USUARIO 
	="Fernando";
	
	private static final String SENHA 
	="sqlserver";
	
	private Statement stm = null;
	private Connection con = null;
	
	public Statement getStatement() {
		return stm;
	}
	
	public ConexaoBD() {
		// TODO Auto-generated constructor stub
		try {
			Class.forName(DRIVER);
			if(con == null){
				con = DriverManager.getConnection(URL, USUARIO, SENHA);
				stm = con.createStatement();
				
				System.out.println("Conexao Realizada com Sucesso!");
			}
		} catch (Exception e) {
			// TODO: handle exception
			System.err.println("Erro ao Criar Conexao!!!");
			e.printStackTrace();
		}
		
	}	
	
	public Connection closeConnection(){
		try {
			if(con != null){
				con.close();
				con = null;
				System.out.println("Conexao Encerrada Com Sucesso!");
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			System.err.println("Erro ao Encerrar Conexao!!!");
		}
		return con;
	}
	
	
	
}
